/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package marsaMaroc.controllers;

import java.util.ArrayList;
import java.util.Date;
import marsaMaroc.dao.PlanActionDAO;
import marsaMaroc.model.PlanAction;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author Administrateur
 */
@Controller
public class PlanActionController {
    
    PlanActionDAO actionDAO = new PlanActionDAO();
    
    @RequestMapping(value = "/addPlan.htm", method = RequestMethod.POST)
    protected ModelAndView add(
            @RequestParam("mode") String mode,
            @RequestParam("date") Date date,
            @RequestParam("solution") String solution
    ) throws Exception {
        
        PlanAction plan = new PlanAction();
        plan.setModeTraitement(mode);
        plan.setDateTraitement(date);
        plan.setSolution(solution);
        
        actionDAO.add(plan);        
        return new ModelAndView("index");
    }

    
    @RequestMapping(value = "/deletePlan.htm", method = RequestMethod.POST)
    protected ModelAndView delete(
            @RequestParam("id") int id
    ) throws Exception {
        
        PlanAction c = (PlanAction) actionDAO.get(id);        
        actionDAO.delete(c);
        return new ModelAndView("index");
    }
    
    
    @RequestMapping(value = "/listPlans.htm", method = RequestMethod.POST)
    protected ModelAndView getAll() throws Exception {
        
        ArrayList<PlanAction> list = (ArrayList<PlanAction>) actionDAO.getAll();
        return new ModelAndView("index","list",list);
    }
    
}
